package com.heatup.apt.common.dao;

import com.heatup.apt.model.CityDiscount;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

@Component
public interface CityDiscountMapper {
    @Delete({
        "delete from city_discount",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into city_discount (id, city_id, ",
        "city_name, discount, ",
        "vip_discount)",
        "values (#{id,jdbcType=INTEGER}, #{cityId,jdbcType=INTEGER}, ",
        "#{cityName,jdbcType=VARCHAR}, #{discount,jdbcType=DECIMAL}, ",
        "#{vipDiscount,jdbcType=DECIMAL})"
    })
    int insert(CityDiscount record);

    int insertSelective(CityDiscount record);

    @Select({
        "select",
        "id, city_id, city_name, discount, vip_discount",
        "from city_discount",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("BaseResultMap")
    CityDiscount selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(CityDiscount record);

    @Update({
        "update city_discount",
        "set city_id = #{cityId,jdbcType=INTEGER},",
          "city_name = #{cityName,jdbcType=VARCHAR},",
          "discount = #{discount,jdbcType=DECIMAL},",
          "vip_discount = #{vipDiscount,jdbcType=DECIMAL}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(CityDiscount record);
    
    @Select({
        "select",
        "ccd.id, ccd.city_id, ccd.city_name, ccd.discount, ccd.vip_discount",
        "from city_discount  ccd left JOIN store_info ssi on ccd.city_id = ssi.city_id",
        "where ssi.id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("BaseResultMap")
    CityDiscount queryCityDiscountByStoreId(Integer storeId);
    
}